<!--
 * @Author: 赵克强 huohuo625@163.com
 * @Date: 2023-11-06 10:39:17
 * @LastEditors: 赵克强 huohuo625@163.com
 * @LastEditTime: 2025-02-13 15:36:23
 * @FilePath: \hy-ui\src\views\app\role\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="app-container" v-loading="loading">
    <el-card class="box-card" shadow="false">
      <div style="padding: 10px 20px 10px 20px; background: #fff">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="前台角色" name="1"></el-tab-pane>
          <el-tab-pane label="后台角色" name="2"></el-tab-pane>
        </el-tabs>
      </div>
      <div class="main">
        <div class="step1" v-if="activeName === '1'">
          <div class="left">
            <!-- <div style="display: flex; align-items: flex-start">
              <el-form
                ref="queryParamsFormRef"
                :model="queryParamsForm"
                label-width="120px"
                :inline="true"
              >
                <el-form-item label="角色名称" prop="roleName">
                  <el-input
                    v-model="queryParamsForm.roleName"
                    placeholder="请输入角色名称"
                  ></el-input>
                </el-form-item>
                <el-form-item label="权限字符" prop="roleKey">
                  <el-input
                    v-model="queryParamsForm.roleKey"
                    placeholder="请输入权限字符"
                  ></el-input>
                </el-form-item>
              </el-form>
              <el-button
                type="primary"
                style="background: #2f54eb; margin-left: 20px"
                icon="el-icon-search"
                @click="getListLeft"
                >查询</el-button
              >
              <el-button
                icon="el-icon-refresh-right"
                @click="() => handleResetLeft('queryParamsFormRef')"
                >重置</el-button
              >
            </div> -->
            <div>
              <el-button type="primary" size="small" icon="el-icon-plus" @click="() => handleAdd()"
                v-hasPermi="['system:role:add']">新增角色</el-button>
              <el-button type="danger" size="small" icon="el-icon-delete" :disabled="multiple" @click="handleDelete"
                v-hasPermi="['system:role:remove']">删除</el-button>
            </div>
            <div class="leftTable" style="margin-top: 8px">
              <el-table :data="roleList" border style="width: 100%" @selection-change="handleSelectionChange"
                highlight-current-row @current-change="handleCurrentChange" size="mini">
                <el-table-column type="selection" width="55" align="center">
                </el-table-column>
                <el-table-column prop="date" label="序号" width="80" align="center">
                  <template slot-scope="scope">
                    {{
                      (queryParamsForm.pageNum - 1) * queryParamsForm.pageSize +
                      (scope.$index + 1)
                    }}
                  </template>
                </el-table-column>
                <el-table-column prop="roleName" label="角色名称" align="center">
                </el-table-column>
                <el-table-column prop="roleKey" label="权限字符" align="center">
                </el-table-column>
                <el-table-column prop="status" label="状态" align="center" width="80"
                  :formatter="(row) => (row.status === '0' ? '正常' : '停用')">
                </el-table-column>
                <el-table-column prop="operate" label="操作" align="center">
                  <template slot-scope="scope">
                    <el-button type="text" @click.stop="() => handleUpdate(scope.row)"
                      v-hasPermi="['system:role:edit']">编辑</el-button>
                    <el-button type="text" style="color: red" @click.stop="() => handleDelete(scope.row)"
                      v-hasPermi="['system:role:remove']">删除</el-button>
                    <el-button type="text" @click.stop="() => handleDataScope(scope.row)"
                      v-hasPermi="['system:role:edit']">数据权限</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <div class="pagination">
                <pagination v-show="totalLeft > 0" :total="totalLeft" :page.sync="queryParamsForm.pageNum"
                  :limit.sync="queryParamsForm.pageSize" @pagination="getListLeft" />
              </div>
            </div>
          </div>
          <div class="right">
            <!-- <div style="display: flex; align-items: flex-start">
              <el-form
                ref="queryParamsFormRefRight"
                :model="queryParamsFormRight"
                label-width="120px"
                :inline="true"
              >
                <el-form-item label="登录账号" prop="userName">
                  <el-input
                    v-model="queryParamsFormRight.userName"
                    placeholder="请输入登录账号"
                  ></el-input>
                </el-form-item>
                <el-form-item label="手机号码" prop="phonenumber">
                  <el-input
                    v-model="queryParamsFormRight.phonenumber"
                    placeholder="请输入手机号码"
                  ></el-input>
                </el-form-item>
              </el-form>
              <el-button
                type="primary"
                style="background: #2f54eb; margin-left: 20px"
                icon="el-icon-search"
                @click="getListRight"
                >查询</el-button
              >
              <el-button
                icon="el-icon-refresh-right"
                @click="() => handleResetRight('queryParamsFormRefRight')"
                >重置</el-button
              >
            </div> -->
            <div>
              <el-button type="primary" size="small" icon="el-icon-plus" @click="openSelectUser"
                v-hasPermi="['system:role:add']">添加用户</el-button>
              <el-button type="danger" size="small" icon="el-icon-delete" @click="cancelAuthUserAll"
                :disabled="multipleUser" v-hasPermi="['system:role:remove']">批量删除</el-button>
            </div>
            <div class="rightTable" style="margin-top: 8px">
              <el-table :data="userList" border style="width: 100%" @selection-change="handleSelectionChangeUser"
                size="mini">
                <el-table-column type="selection" width="55" align="center" fixed="left">
                </el-table-column>
                <el-table-column prop="date" label="序号" width="80" align="center">
                  <template slot-scope="scope">
                    {{
                      (queryParamsFormRight.pageNum - 1) *
                      queryParamsFormRight.pageSize +
                      (scope.$index + 1)
                    }}
                  </template>
                </el-table-column>
                <el-table-column label="登录账号" prop="userName" width="160" align="center" :show-overflow-tooltip="true" />
                <el-table-column prop="nickName" label="姓名" align="center" width="120px">
                </el-table-column>
                <el-table-column prop="phonenumber" label="手机" align="center" width="120px">
                </el-table-column>
                <el-table-column prop="userType" label="用户类型" width="120px" :show-overflow-tooltip="true" align="center"
                  :formatter="(row) =>
                    row.userType
                      ? selectDictLabel(dict.type.sys_user_type, row.userType)
                      : '--'
                    ">
                </el-table-column>
                <el-table-column prop="status" label="状态" align="center" width="80px"
                  :formatter="(row) => (row.status === '0' ? '正常' : '停用')">
                </el-table-column>
                <el-table-column prop="operate" label="操作" align="center" width="200px" fixed="right">
                  <template slot-scope="scope">
                    <el-button type="text" style="color: red" @click="cancelAuthUser(scope.row)"
                      v-hasPermi="['system:role:remove']">删除</el-button>
                    <el-button type="text" @click="handleDataScope(scope.row, true)">数据权限</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <div class="pagination">
                <pagination v-show="totalRight > 0" :total="totalRight" :page.sync="queryParamsFormRight.pageNum"
                  :limit.sync="queryParamsFormRight.pageSize" @pagination="getListRight" />
              </div>
            </div>
          </div>
        </div>
        <div class="step2" v-if="activeName === '2'">
          <div class="left">
            <div>
              <el-button type="primary" size="small" icon="el-icon-plus" @click="() => handleAdd()"
                v-hasPermi="['system:role:add']">新增角色</el-button>
              <el-button type="danger" size="small" icon="el-icon-delete" :disabled="multiple" @click="handleDelete"
                v-hasPermi="['system:role:remove']">删除</el-button>
            </div>
            <div class="leftTable" style="margin-top: 8px">
              <el-table :data="step2LeftList" border style="width: 100%" @selection-change="handleSelectionChange"
                highlight-current-row @current-change="handleCurrentChange" size="mini">
                <el-table-column type="selection" width="55" align="center">
                </el-table-column>
                <el-table-column prop="date" label="序号" width="80" align="center">
                  <template slot-scope="scope">
                    {{
                      (step2LeftParams.pageNum - 1) * step2LeftParams.pageSize +
                      (scope.$index + 1)
                    }}
                  </template>
                </el-table-column>
                <el-table-column prop="roleName" label="角色名称" align="center">
                </el-table-column>
                <el-table-column prop="roleKey" label="权限字符" align="center">
                </el-table-column>
                <el-table-column prop="status" label="状态" align="center" width="80"
                  :formatter="(row) => (row.status === '0' ? '正常' : '停用')">
                </el-table-column>
                <el-table-column prop="operate" label="操作" align="center">
                  <template slot-scope="scope" v-if="scope.row.roleId !== 1">
                    <el-button type="text" @click.stop="() => handleUpdate(scope.row)"
                      v-hasPermi="['system:role:edit']">编辑</el-button>
                    <el-button type="text" style="color: red" @click.stop="() => handleDelete(scope.row)"
                      v-hasPermi="['system:role:remove']">删除</el-button>
                    <el-button type="text" @click.stop="() => handleDataScope(scope.row)"
                      v-hasPermi="['system:role:edit']">数据权限</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <div class="pagination">
                <pagination v-show="step2LeftTotal > 0" :total="step2LeftTotal" :page.sync="step2LeftParams.pageNum"
                  :limit.sync="step2LeftParams.pageSize" @pagination="getList_step2_left" />
              </div>
            </div>
          </div>
          <div class="right">
            <div>
              <el-button type="primary" size="small" icon="el-icon-plus" @click="openSelectUser"
                v-hasPermi="['system:role:add']" :disabled="!userList.length">添加用户</el-button>
              <el-button type="danger" size="small" icon="el-icon-delete" @click="cancelAuthUserAll"
                :disabled="multipleUser" v-hasPermi="['system:role:remove']">批量删除</el-button>
            </div>
            <div class="rightTable" style="margin-top: 8px">
              <el-table :data="userList" border style="width: 100%" @selection-change="handleSelectionChangeUser"
                size="mini">
                <el-table-column type="selection" width="55" align="center" fixed="left">
                </el-table-column>
                <el-table-column prop="date" label="序号" width="80" align="center">
                  <template slot-scope="scope">
                    {{
                      (queryParamsFormRight.pageNum - 1) *
                      queryParamsFormRight.pageSize +
                      (scope.$index + 1)
                    }}
                  </template>
                </el-table-column>
                <el-table-column label="登录账号" prop="userName" width="160" align="center" :show-overflow-tooltip="true" />
                <el-table-column prop="nickName" label="姓名" align="center" width="120px">
                </el-table-column>
                <el-table-column prop="phonenumber" label="手机" align="center" width="120px">
                </el-table-column>
                <el-table-column prop="userType" label="用户类型" width="120px" :show-overflow-tooltip="true" align="center"
                  :formatter="(row) =>
                    row.userType
                      ? selectDictLabel(dict.type.sys_user_type, row.userType)
                      : '--'
                    ">
                </el-table-column>
                <el-table-column prop="status" label="状态" align="center" width="80px"
                  :formatter="(row) => (row.status === '0' ? '正常' : '停用')">
                </el-table-column>
                <el-table-column prop="operate" label="操作" align="center" width="200px" fixed="right">
                  <template slot-scope="scope">
                    <el-button type="text" style="color: red" @click="cancelAuthUser(scope.row)"
                      v-hasPermi="['system:role:remove']">删除45354</el-button>

                  </template>

                </el-table-column>
              </el-table>
              <div class="pagination">
                <pagination v-show="totalRight > 0" :total="totalRight" :page.sync="queryParamsFormRight.pageNum"
                  :limit.sync="queryParamsFormRight.pageSize" @pagination="getListRight" />
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-card>
    <!-- 添加或修改角色配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="40%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="角色名称" prop="roleName">
          <el-input v-model="form.roleName" placeholder="请输入角色名称" />
        </el-form-item>
        <el-form-item prop="roleKey">
          <span slot="label"> 权限字符 </span>
          <el-input v-model="form.roleKey" placeholder="请输入权限字符" />
        </el-form-item>
        <el-form-item label="角色顺序" prop="roleSort">
          <el-input-number v-model="form.roleSort" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.value">{{ dict.label
            }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 分配角色数据权限对话框 -->
    <el-dialog :title="title" :visible.sync="openDataScope" width="40%" append-to-body>
      <el-form :model="form" label-width="80px">
        <el-form-item label="角色名称" v-if="!isUserPower">
          <el-input v-model="form.roleName" :disabled="true" />
        </el-form-item>
        <el-form-item label="权限字符" v-if="!isUserPower">
          <el-input v-model="form.roleKey" :disabled="true" />
        </el-form-item>
        <el-form-item label="权限范围">
          <el-select v-model="form.userDataScope" @change="dataScopeSelectChange">
            <el-option v-for="item in dataScopeOptions" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数据权限" v-show="form.userDataScope == 2">
          <el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($event, 'dept')">展开/折叠</el-checkbox>
          <el-checkbox v-model="deptNodeAll" @change="handleCheckedTreeNodeAll($event, 'dept')">全选/全不选</el-checkbox>
          <el-checkbox v-model="form.deptCheckStrictly"
            @change="handleCheckedTreeConnect($event, 'dept')">父子联动</el-checkbox>
          <el-tree class="tree-border" :data="deptOptions" show-checkbox default-expand-all ref="dept" node-key="id"
            :check-strictly="!form.deptCheckStrictly" empty-text="加载中，请稍候" :props="defaultProps"></el-tree>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitDataScope">确 定</el-button>
        <el-button @click="cancelDataScope">取 消</el-button>
      </div>
    </el-dialog>
    <select-user ref="select" :roleId="currentRow && currentRow.roleId" @ok="getListRight" :activeName="activeName" />
  </div>
</template>

<script>
import {
  listRole,
  getRole, 
  delRole,
  addRole,
  updateRole,
  dataScope,
  changeRoleStatus,
  deptTreeSelect,
  allocatedUserList,
  authUserCancel,
  authUserCancelAll,
  setUserPower
} from "@/api/app/role";
import selectUser from "./selectUser";
import * as step2Api from "@/api/system/role";
import {
  treeselect as menuTreeselect,
  roleMenuTreeselect,
} from "@/api/system/menu";
import { listDept } from "@/api/system/dept";
import {
  getUser,
} from "@/api/system/user";

export default {
  name: "Role",
  components: { selectUser },
  dicts: ["sys_normal_disable", "sys_user_type"],
  data() {
    return {
      defaultProps: {
        children: "children",
        label: "label",
      },
      dataScopeOptions: [
        {
          value: "1",
          label: "全部数据权限",
        },
        {
          value: "2",
          label: "自定数据权限",
        },
        {
          value: "3",
          label: "本部门数据权限",
        },
        {
          value: "4",
          label: "本部门及以下数据权限",
        },
        {
          value: "5",
          label: "仅本人数据权限",
        },
      ],
      queryParamsForm: {
        pageNum: 1,
        pageSize: 10,
      },
      queryParamsFormRight: {
        pageNum: 1,
        pageSize: 10,
      },
      totalLeft: 0,
      roleList: [],
      // 部门列表
      deptOptions: [],
      // 遮罩层
      loading: true,
      title: "",
      open: false,
      rules: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" },
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" },
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" },
        ],
      },
      form: {},
      multiple: true,
      multipleUser: true,
      ids: [],
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      userList: [],
      totalRight: 0,
      currentRow: {},
      userIds: [],
      keys: [],
      activeName: "1",
      step2LeftList: [],
      step2LeftTotal: 0,
      step2LeftParams: {
        pageNum: 1,
        pageSize: 10,
      },
      isUserPower: false,
      deptExpand: false,
      deptNodeAll: false
    };
  },
  created() {
    this.getListLeft();
  },
  methods: {
    handleClick() {
      this.form = {};
      this.userList = []
      if (this.activeName === "1") {
        this.getListLeft();
      } else {
        this.getList_step2_left();
      }
    },
    getList_step2_left() {
      this.loading = true;
      step2Api.listRole(this.step2LeftParams).then((response) => {
        this.step2LeftList = response.rows;
        this.step2LeftTotal = response.total;
        this.loading = false;
      });
    },
    handleCurrentChange(val) {
      this.currentRow = val
      if (val.roleId === 1) {
        return this.$modal.msgError("不允许操作超级管理员角色");
      }
      this.getListRight();
    },
    /** 查询角色列表 */
    getListLeft() {
      this.loading = true;
      listRole(this.queryParamsForm).then((response) => {
        this.roleList = response.rows;
        this.totalLeft = response.total;
        this.loading = false;
      });
    },
    getListRight() {
      if (!this.currentRow?.roleId) return;
      this.loading = true;
      allocatedUserList({
        ...this.queryParamsFormRight,
        roleId: this.currentRow?.roleId,
      }).then((response) => {
        this.userList = response.rows;
        this.totalRight = response.total;
        this.loading = false;
      });
    },
    handleResetLeft(ref) {
      this.resetForm(ref);
      this.getListLeft();
    },
    handleResetRight(ref) {
      this.resetForm(ref);
      this.getListRight();
    },
    /** 新增按钮操作 */
    handleAdd() {
      // this.reset();
      this.form = {};
      this.open = true;
      this.title = "添加角色";
    },
    cancel() {
      this.open = false;
      this.form = {};
    },
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.roleId != undefined) {
            updateRole({ ...this.form, menuIds: [] }).then((response) => {
              this.$modal.msgSuccess("编辑成功");
              this.open = false;
              if (this.activeName === "1") {
                returnthis.getListLeft();
              } else {
                this.getList_step2_left();
              }
            });
          } else {
            addRole({
              ...this.form,
              platformType: this.activeName === "1" ? "front" : undefined,
              deptCheckStrictly: true,
              deptIds: [],
              menuCheckStrictly: true,
              menuIds: [],
            }).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              if (this.activeName === "1") {
                this.getListLeft();
              } else {
                this.getList_step2_left();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.roleId || this.ids;
      const keysArr = row.roleKey || this.keys;
      this.$modal
        .confirm('是否确认删除角色编号为"' + keysArr + '"的数据项？')
        .then(() => {
          if (this.activeName === "1") {
            return delRole(roleIds);
          } else {
            return step2Api.delRole(roleIds);
          }
        })
        .then(() => {
          if (this.activeName === "1") {
            this.getListLeft();
          } else {
            this.getList_step2_left();
          }
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    handleSelectionChange(selection) {

      this.ids = selection.map((item) => item.roleId);
      this.keys = selection.map((item) => item.roleKey);
      this.multiple = !selection.length;
    },
    handleUpdate(row) {
      // this.reset();
      this.form = {};
      (this.activeName === "1"
        ? getRole(row.roleId)
        : step2Api.getRole(row.roleId)
      ).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改角色";
      });
    },
    /** 根据角色ID查询部门树结构 */
    getDeptTree(roleId) {
      return deptTreeSelect(roleId).then((response) => {
        this.deptOptions = response.data.depts;
        return response;
      });
    },
    /** 分配数据权限操作 */
    async handleDataScope(row, isUser) {
      // this.reset();
      this.form = {};
      this.isUserPower = isUser
      if (isUser) {
        const res = await getUser(row.userId)
        let userCheckList = []
        if (res.code === 200) {
          this.form = { ...this.form, userDataScope: res.data.user.userDataScope, deptCheckStrictly: res.data.user.deptCheckStrictly }
          userCheckList = res.data.user.deptIds
        }
        listDept().then((response) => {
          
          const list = response.data
          list.map(item => {
            item.label = item.deptName
            item.id = item.deptId
            return item
          })
          this.deptOptions = this.handleTree(list, "deptId");
        });
        this.openDataScope = true;
        this.form.userId = row.userId
        this.$nextTick(() => {
          this.$refs.dept.setCheckedKeys(userCheckList);
        });
      } else {
        const deptTreeSelect = this.getDeptTree(row.roleId);
        getRole(row.roleId).then((response) => {
          this.form = response.data;
          this.openDataScope = true;
          this.$nextTick(() => {
            deptTreeSelect.then((res) => {
              this.$refs.dept.setCheckedKeys(res.data.checkedKeys);
            });
          });

        });
      }
      this.title = "分配数据权限";
    },
    /** 选择角色权限范围触发 */
    dataScopeSelectChange(value) {
      if (value !== "2") {
        this.$refs.dept.setCheckedKeys([]);
      }
    },
    // 树权限（展开/折叠）
    handleCheckedTreeExpand(value, type) {
      if (type == "menu") {
        let treeList = this.menuOptions;
        for (let i = 0; i < treeList.length; i++) {
          this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
        }
      } else if (type == "dept") {
        let treeList = this.deptOptions;
        console.log(treeList);
        for (let i = 0; i < treeList.length; i++) {
          this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value;
        }
      }
    },
    // 树权限（全选/全不选）
    handleCheckedTreeNodeAll(value, type) {
      if (type == "menu") {
        this.$refs.menu.setCheckedNodes(value ? this.menuOptions : []);
      } else if (type == "dept") {
        this.$refs.dept.setCheckedNodes(value ? this.deptOptions : []);
      }
    },
    // 树权限（父子联动）
    handleCheckedTreeConnect(value, type) {
      if (type == "menu") {
        this.form.menuCheckStrictly = value ? true : false;
      } else if (type == "dept") {
        this.form.deptCheckStrictly = value ? true : false;
      }
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      // this.reset();
    },
    // 所有部门节点数据
    getDeptAllCheckedKeys() {
      // 目前被选中的部门节点
      let checkedKeys = this.$refs.dept.getCheckedKeys();
      // 半选中的部门节点
      let halfCheckedKeys = this.$refs.dept.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      return checkedKeys;
    },
    submitDataScope() {
      // 
      if (this.isUserPower) {
        const list = this.getDeptAllCheckedKeys();
        this.form.deptIds = list?.length ? list : undefined
        setUserPower(this.form).then((response) => {
          if (response.code === 200) {
            this.$modal.msgSuccess("配置成功");
            this.openDataScope = false;
            this.getListRight();
          } else {
            this.$modal.msgError(res.msg);
          }
        });
      } else {
        if (this.form.roleId != undefined) {
          this.form.deptIds = this.getDeptAllCheckedKeys();
          dataScope(this.form).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.openDataScope = false;
            if (this.activeName === "1") {
              this.getListLeft();
            } else {
              this.getList_step2_left();
            }
          });
        }
      }

    },
    /** 批量取消授权按钮操作 */
    cancelAuthUserAll(row) {
      const roleId = this.currentRow.roleId;
      const userIds = this.userIds.join(",");
      this.$modal
        .confirm("是否删除选中用户？")
        .then(function () {
          return authUserCancelAll({ roleId: roleId, userIds: userIds });
        })
        .then(() => {
          this.getListRight();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 取消授权按钮操作 */
    cancelAuthUser(row) {
      const roleId = this.currentRow.roleId;
      this.$modal
        .confirm('确认要删除该用户"' + row.userName + '"角色吗？')
        .then(function () {
          return authUserCancel({ userId: row.userId, roleId: roleId });
        })
        .then(() => {
          this.getListRight();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    // 多选框选中数据
    handleSelectionChangeUser(selection) {
      this.userIds = selection.map((item) => item.userId);
      this.multipleUser = !selection.length;
    },
    /** 打开授权用户表弹窗 */ 
    openSelectUser() {
      this.$refs.select.show();
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  padding: 10px;

  ::v-deep .el-card {
    background: #f1f1f1 !important;

    .el-card__body {
      padding: 0;
    }
  }

  .main {

    .step1,
    .step2 {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
    }

    .left {
      background: #fff;
      width: 50%;
      margin-right: 10px;
      min-height: 85vh;
      padding: 0 20px 20px 20px;
    }

    .right {
      background: #fff;
      width: 50%;
      min-height: 85vh;
      padding: 0 20px 20px 20px;
    }
  }
}
</style>

